let {v4}=require('uuid');
let qiniu=require('qiniu')
let express=require('express');
let router = express.Router();


router.post('/', function(req, res, next) {
  var key=v4();
  var accessKey = '3FE-7P-_Q_gwfjK-WldkeAZOZwrxIPlzQ-_CmDE1';
  var secretKey = 'bCXgSUOXejHHl8P2-6AIs8G4_W9pUGeCDusAcyxk';
  var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
  var options = {
    scope: 'sunshine-test'+':'+key,
    expires: 7200,
    returnBody: `{
      "src":"http://orwb91me7.bkt.clouddn.com/${key}"
    }`
  };
  var putPolicy = new qiniu.rs.PutPolicy(options);
  var uploadToken=putPolicy.uploadToken(mac);
  console.log(uploadToken)
  res.send({uptoken:uploadToken,key})
});

module.exports = router;
